<?php

require_once 'Pipes/Decorator.php';
require_once 'PipesImpl/Visitable.php';

class Pipes_Xml_NodeList
	extends Pipes_Decorator
	implements Iterator, PipesImpl_Visitable

{
	public function __construct(DOMNodeList $nodeList) {
		$this->_decorated = $nodeList;
	}
	
	public function current() {
		return new Pipes_Xml_Element(
			$this->_decorated->item($this->key())
		);
	}
	
	public function key() 
	{ 
		return $this->_cursor;
	}
	public function next() 
	{
		$this->_cursor++;
	}
	public function rewind() 
	{
		$this->_cursor = 0;
	}
	
	public function valid() 
	{
		return $this->_cursor < $this->_decorated->length;
	}
	
	public function accept(PipesImpl_Visitor $visitor) {
		return $visitor->visit($this);
	}
	
	public function item($key) {
		return new Pipes_Xml_Element($this->_decorated->item($key));
	}
}
